<?php
    require("../config.php");
    if (isset($_GET['btnSubmit'])) {
        $item_name = $_GET['txtItemName'];
        $item_price = $_GET['txtItemPrice'];
        $item_urlimg = $_GET['txtURLImg'];
        $item_status = $_GET['sltStatus'];
        $item_country = $_GET['txtItemCountry'];
        $item_detail = $_GET['txtDetail'];
        $item_date = $_GET['txtDate'];
        $item_date = str_replace("-","/", $item_date);
        mysql_query("INSERT INTO items(id, item_name, item_price, item_imgurl, item_status, item_country, item_detail, item_input) VALUES('', '". $item_name. "', '".$item_price."', '".$item_urlimg."', '".$item_status."', '".$item_country."', '".$item_detail."', '".$item_date."')");
        echo 'Success!!!';
        unset($item_name);
        unset($item_price);
        unset($item_urlimg);
        unset($item_status);
        unset($item_country);
        unset($item_detail);
        unset($item_date);
    }
?>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="author" content="Invisible Man" />
	<title>Admin Control Panel</title>
    <link rel="stylesheet" href="styles.css" />
    <link rel="stylesheet" href="../js/jquery-ui.css" />
      <script src="../js/jquery-1.9.1.js"></script>
      <script src="../js/jquery-ui.js"></script>
      <script type="text/javascript" src="js/ad_additem.js"></script>
      <script>
      $(function() {
        $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd'});
      });
      </script>
</head>

<body>
    <table align="center"><tr><td width="450px">
        <form name="additem" method="GET" action="" onsubmit="return checkInput();">
            <fieldset>
                <legend>Adding your Item</legend>
                <table>
                    <tr>
                        <td width="120px">
                            Item Name:
                        </td>
                        <td>
                            <input type="text" id="i_Name" name="txtItemName" size="40px"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Item Prize:
                        </td>
                        <td>
                            <input type="text" name="txtItemPrice" size="40px"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Item Image:
                        </td>
                        <td>
                            <input type="text" name="txtURLImg" size="40px"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Item Status:
                        </td>
                        <td>
                            <select name="sltStatus">
                                <option value="SELL">SELL</option>
                                <option value="SOLD">SOLD</option>
                                <option value="LIMIT">LIMIT</option>
                                <option value="NONE">NONE</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Item Country:
                        </td>
                        <td>
                            <input type="text" name="txtItemCountry" size="40px"/>
                        </td>
                    </tr>
                                        <tr>
                        <td>
                            Item Detail:
                        </td>
                        <td>
                            <textarea name="txtDetail" cols="31" rows="5"></textarea>
                        </td>
                    </tr>
                                        <tr>
                        <td>
                            Item Input Date:
                        </td>
                        <td>
                            <input type="text" id="datepicker" name="txtDate" />
                        </td>
                    </tr>
                    </tr>
                    <tr>
                        <td>
                            
                        </td>
                        <td>
                            <input type="submit" name="btnSubmit" />
                            <input type="reset" name="btnReset" />
                        </td>
                    </tr>
                </table>
            </fieldset>
        </form>
    </tr></td>
    </table>
    <table align="center" class="manage">
        <tr>
            <td class="td-center">
                ID
            </td>
            <td class="td-center" width="100px">
                Name
            </td>
            <td class="td-center" width="100px">
                Prize
            </td>
            <td class="td-center" width="100px">
                Thumbnail
            </td>
            <td class="td-center" width="100px">
                Status
            </td>
            <td class="td-center" width="100px">
                Country
            </td>
            <td class="td-center" width="100px">
                Date Input
            </td>
        </tr>
        <?php 
            $result = mysql_query("SELECT * FROM items");
            while ($row = mysql_fetch_assoc($result)){
                echo '<tr>';
                echo '<td class="td-center">'.$row['id'].'</td>';
                echo '<td class="td-center">'.$row['item_name'].'</td>';
                echo '<td class="td-center">'.$row['item_price'].'$USD</td>';
                if (strpos($row['item_imgurl'], "http") === false) {
                    echo '<td class="td-center"><img src="../'.$row['item_imgurl'].'" width="50px" /></td>';
                }
                else {
                    echo '<td class="td-center"><img src="'.$row['item_imgurl'].'" width="50px" /></td>';
                }
                echo '<td class="td-center">'.$row['item_status'].'</td>';
                echo '<td class="td-center">'.$row['item_country'].'</td>';
                echo '<td class="td-center">'.$row['item_input'].'</td>';
                echo '<td class="td-center"><a href="#">Edit</a></td>';
                echo '</tr>';
            }
        ?>
    </table>
    

</body>
</html>